package com.bancomer.batch;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.bancomer.batch.pojo.Alert;
import com.bancomer.batch.pojo.FileHelper;
import com.bancomer.batch.pojo.PigScript;
import com.bancomer.batch.util.FilesWriter;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;

public class TestXml {

	public static void main(String[] args) {
		/*XStream xstream = new XStream(new StaxDriver());
		//String localPath = "C:\\Users\\ggarfias\\Documents\\BANCOMER_BIGDATA\\AutomationDocuments\\";
		String localPath = args[0];
		Properties properties;
		
		FileHelper layout = new FileHelper(); //Archivo de layout
		FileHelper load1 = new FileHelper(); //TABLA001.BIGDATA
		FileHelper load2 = new FileHelper(); //AMDT010.BIGDATA.FORM
		FileHelper load3 = new FileHelper(); //TABLA008.BIGDATA
		FileHelper load4 = new FileHelper(); //ALERTEXC.BIGDATA.D1140509
		FileHelper load5 = new FileHelper(); //AMDT011.BIGDATA.FORM
		FileHelper load6 = new FileHelper(); //MOVONBA0.BIGDATA.D1140509
		
		List<String> validationClass = null;
		//atrubutos layout
		layout.setLocalPath(localPath);
		layout.setName("formatoLayout.txt");
		layout.setType(Constants.FILE_PIG_LOAD);
		validationClass = new ArrayList<String>();
		validationClass.add("com.bancomer.batch.validators.impl.LayoutValidator");
		layout.setValidationClass(validationClass);
		//atributos load1
		load1.setLocalPath(localPath);
		load1.setName("TABLA001.BIGDATA_2.txt");
		load1.setType(Constants.FILE_HDFS);
		load1.setHdfsPath("hdfs://localhost.localdomain:8022/user/cloudera/");
		
		//atributos load2
		properties = new Properties();
		properties.put("auxiliaryValidator", localPath+"AMDT006.BIGDATA.FORM.txt");
		load2.setLocalPath(localPath);
		load2.setName("AMDT010.BIGDATA.FORM.txt");
		load2.setType(Constants.FILE_PIG_PROPERTIES);
		validationClass = new ArrayList<String>();
		validationClass.add("com.bancomer.batch.validators.impl.SensitiveCollectiveValidator");
		load2.setValidationClass(validationClass);
		load2.setProperties(properties);
		
		//atributos load3
		load3.setLocalPath(localPath);
		load3.setName("TABLA008.BIGDATA.txt");
		load3.setType(Constants.FILE_HDFS);
		load3.setHdfsPath("hdfs://localhost.localdomain:8022/user/cloudera/");
		
		//atributos load4
		properties = new Properties();
		properties.put("containsDisableAlert", "11FRAU-INT-006");
		properties.put("11FRAU-INT-006",false);
		load4.setLocalPath(localPath);
		load4.setName("ALERTEXC.BIGDATA.D1140509.txt");
		load4.setType(Constants.FILE_PIG_PROPERTIES);
		load4.setFastValidation("exist empty");
		validationClass = new ArrayList<String>();
		validationClass.add("com.bancomer.batch.validators.impl.EnableAlertValidator");
		validationClass.add("com.bancomer.batch.validators.impl.DisableByOptionAlertValidator");
		load4.setValidationClass(validationClass);
		load4.setProperties(properties);
		
		//atributos load5
		load5.setLocalPath(localPath);
		load5.setName("AMDT011.BIGDATA.FORM.txt");
		load5.setType(Constants.FILE_PIG_PROPERTIES);
		validationClass = new ArrayList<String>();
		validationClass.add("com.bancomer.batch.validators.impl.ConceptAlertValidator");
		load5.setValidationClass(validationClass);
		
		//atributos load6
		load6.setLocalPath(localPath);
		load6.setName("MOVONBA0.BIGDATA.D1140509.txt");
		load6.setType(Constants.FILE_HDFS);
		load6.setHdfsPath("hdfs://localhost.localdomain:8022/user/cloudera/");
		
		PigScript pigScript = new PigScript();
		pigScript.setName("MovimientosAlertexc.pig");
		pigScript.setPath("/home/cloudera/Documents/FASE3/");
		
		FileHelper clientesCS = new FileHelper();
		clientesCS.setName("clientes_cs");
		clientesCS.setHdfsPath("hdfs://localhost.localdomain:8022/user/cloudera/");
		clientesCS.setLocalPath("/home/cloudera/Documents/FASE3/AutomationDocuments/");
		
		FileHelper clientesCSContratos = new FileHelper();
		clientesCSContratos.setName("clientes_cs_contratos");
		clientesCSContratos.setHdfsPath("hdfs://localhost.localdomain:8022/user/cloudera/");
		clientesCSContratos.setLocalPath("/home/cloudera/Documents/FASE3/AutomationDocuments/");
		
		FileHelper contratosMovimientos = new FileHelper();
		contratosMovimientos.setName("movimientos_contratos");
		contratosMovimientos.setHdfsPath("hdfs://localhost.localdomain:8022/user/cloudera/");
		contratosMovimientos.setLocalPath("/home/cloudera/Documents/FASE3/AutomationDocuments/");
		
		FileHelper movimientosAlertexc = new FileHelper();
		movimientosAlertexc.setName("movimientos_alertexc");
		movimientosAlertexc.setHdfsPath("hdfs://localhost.localdomain:8022/user/cloudera/");
		movimientosAlertexc.setLocalPath("/home/cloudera/Documents/FASE3/AutomationDocuments/");
		
		List<FileHelper> pigOutputfiles = new ArrayList<FileHelper>();
		pigOutputfiles.add(clientesCS);
		pigOutputfiles.add(clientesCSContratos);
		pigOutputfiles.add(contratosMovimientos);
		pigOutputfiles.add(movimientosAlertexc);
		
		pigScript.setOutputResultsFiles(pigOutputfiles);
		
		Alert alert= new Alert();
		
		List<FileHelper> hdfsFiles = new ArrayList<FileHelper>();
		List<FileHelper> outputFiles = new ArrayList<FileHelper>();
		List<FileHelper> propertiesFiles = new ArrayList<FileHelper>();
		
		propertiesFiles.add(layout);
		propertiesFiles.add(load4);
		propertiesFiles.add(load2);
		propertiesFiles.add(load5);
		
		hdfsFiles.add(load1);
		hdfsFiles.add(load3);
		hdfsFiles.add(load6);
		
		alert.setName("ALERTA06");
		alert.setDescription("Alerta de movimientos sin tarjeta");
		alert.setPropertiesFiles(propertiesFiles);
		alert.setHdfsFiles(hdfsFiles);
		alert.setOutputFiles(outputFiles);
		alert.setPigScript(pigScript);
		
		xstream.alias("Alert", Alert.class);
		xstream.alias("FileHelper", FileHelper.class);
		xstream.alias("PigScript", PigScript.class);
		
		String xml = xstream.toXML(alert);
		System.out.println(xml);
		try{
			FilesWriter.writeFile(xml, localPath+alert.getName()+".xml",false);
			FilesWriter.formatXMLFile(localPath+alert.getName()+".xml");
		}
		catch(Exception e){
			e.getMessage();
			e.printStackTrace();
		}*/
		
	}

}
